﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using DAO;
using BUS;
namespace CuaHangHoa
{
    public partial class form_themmathang : Form
    {
        public form_themmathang()
        {
            InitializeComponent();
        }


        public delegate void DoEvent();
        public event DoEvent RefreshDgv;

        private void ThemMH()
        {
            try
            {
                quanlymathang_DTO mhDTO = new quanlymathang_DTO();
                mhDTO.tenhang  = txt_tenhang .Text.Trim();
                if (comboBox_XuatxU.Text == "Đà Lạt")
                {
                    mhDTO.xuatxu = 1;
                }
                if (comboBox_XuatxU.Text == "Đài Loan")
                {
                    mhDTO.xuatxu = 2;
                }
             //   mhDTO.xuatxu  = int.Parse (txt_xuatxu.Text.Trim());
                mhDTO.donvitinh  = txt_donvitinh.Text.Trim();
                mhDTO.gianhap  = int.Parse (txt_gianhap.Text.Trim());
                mhDTO.soluongton  = int.Parse (txt_soluongton.Text.Trim());
                mhDTO.tinhtrang =  txt_tinhtrang.Text.Trim();
                mhDTO.ghichu= txt_ghichu.Text.Trim();
                mhDTO.dongia = int.Parse (txt_dongia.Text.Trim());
                if (cbx_idlloai.Text == "Hoa")
                {
                    mhDTO.idlloai  = 1;
                }
                if (cbx_idlloai.Text == "Chậu")
                {
                    mhDTO.idlloai = 2;
                }

               
                int kq;
                quanlymathang_BUS bus = new quanlymathang_BUS();
                kq = bus.ThemMatHang(mhDTO);
                

                if (kq == 1)
                {
                    //this.RefreshDgv();
                    
                    MessageBox.Show("Thêm thành công");
                }
                else
                {
                    MessageBox.Show("Thêm thất bại");
                }
                txt_tenhang.Focus();
            }
            catch (System.Exception ex)
            {
                errorProvider1.SetError(txt_tenhang, "BẠN CHƯA NHẬP ĐẦY ĐỦ THÔNG TIN HOẶC TÊN HOA ĐÃ TỒN TẠI");
               txt_tenhang.Focus();
            }

        }

        private void form_themmathang_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            ThemMH();
            errorProvider1.Clear();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            txt_tenhang.Text = "";
            comboBox_XuatxU.Text = "";
            txt_donvitinh.Text = "";
            txt_soluongton.Text = "";
            txt_gianhap.Text = "";
            txt_tinhtrang.Text = "";
            txt_ghichu.Text = "";
            txt_dongia.Text = "";
            cbx_idlloai.Text = "";
            txt_tenhang.Focus();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void txt_tenhang_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_donvitinh_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_soluongton_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_gianhap_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_tinhtrang_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_ghichu_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void txt_dongia_TextChanged(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void comboBox_XuatxU_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void cbx_idlloai_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void txt_donvitinh_KeyPress(object sender, KeyPressEventArgs e)
        {
            
        }

        private void txt_soluongton_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
                errorProvider1.SetError(txt_soluongton , "Chi được nhập số");

            }
        }

        private void txt_gianhap_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
                errorProvider1.SetError(txt_gianhap, "Chi được nhập số");
                
            }
        }

        private void txt_dongia_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
                errorProvider1.SetError(txt_dongia, "Chi được nhập số");

            }
        }
    }
}
